package holdtime.xlxc.activities.main;

import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import holdtime.xlxc.R;
import holdtime.xlxc.base.BaseActivity;
import holdtime.xlxc.tools.util.ImageUtil;

public class LoadActivity extends BaseActivity {

    private Button skip;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        isSetActionBar = false;
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_load);

        ImageView loadImg = (ImageView) findViewById(R.id.load_img);
        loadImg.setImageBitmap(ImageUtil.streamBitmap(this, R.drawable.load));

        skip = (Button) findViewById(R.id.skip);

        final CountDownTimer timer = new CountDownTimer(5000, 1000) {
            public void onTick(long millisUntilFinished) {
                if (millisUntilFinished / 1000 == 1) {
                    startActivity(new Intent(getApplication(), MainActivity.class));
                    LoadActivity.this.finish();
                }
                skip.setText("跳过" + millisUntilFinished / 1000);
            }

            public void onFinish() {
            }
        };

        skip.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(getApplication(), MainActivity.class));
                LoadActivity.this.finish();
                timer.cancel();
            }
        });
        timer.start();
    }
}
